package com.zuper.demo.sessionlogin.config;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//效能过滤器-打印请求处理时间
@WebFilter("/*")
public class MyPerformanceFilter extends HttpFilter {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		//getServletContext().log("Request coming: " + request.getContextPath()+request.getServletPath()+ (null==request.getPathInfo()?"":request.getPathInfo()));
		getServletContext().log("Request coming: " + request.getRequestURI());
		getServletContext().log("Request process before");
		long begin = System.currentTimeMillis();
		chain.doFilter(request, response);
		getServletContext().log("Request process after");
		getServletContext().log("Request process in " + (System.currentTimeMillis() - begin) + " ms");
	}
}
